<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑留言</title>
    <link th:href="@{/static/bootstrap-5.3.0/css/bootstrap.min.css}" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0;
        }

        .form-container {
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
            padding: 30px;
            width: 100%;
            max-width: 600px;
        }

        .form-title {
            text-align: center;
            color: #4f6ef6;
            margin-bottom: 30px;
            font-weight: 600;
        }

        .form-control {
            border-radius: 8px;
            padding: 12px 15px;
            transition: all 0.3s ease;
        }

        .form-control:focus {
            border-color: #4f6ef6;
            box-shadow: 0 0 0 3px rgba(79, 110, 234, 0.2);
        }

        .btn-submit {
            width: 100%;
            padding: 12px;
            background-color: #4f6ef6;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .btn-submit:hover {
            background-color: #3a56d4;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(79, 110, 234, 0.3);
        }

        .alert-warning {
            background-color: #fff3cd;
            border-color: #ffeeba;
            color: #856404;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 20px;
        }

        .form-group-spacing {
            margin-bottom: 8px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="form-container">
        <h2 class="form-title">编辑留言</h2>

        <!-- 权限校验提示 -->
        <div th:unless="${message.writer == session.currentUser.studentName}" class="alert-warning">
            警告：您无权编辑他人的留言！
        </div>

        <!-- 仅当当前用户是作者时显示编辑表单 -->
        <form th:if="${message.writer == session.currentUser.studentName}"
              th:action="@{/messages/update}"
              method="post">

            <!-- 隐藏字段携带messageID -->
            <input type="hidden" name="messageID" th:value="${message.messageID}">

            <!-- 标题 -->
            <div class="mb-3 form-group-spacing">
                <label class="form-label">标题</label>
                <input type="text"
                       class="form-control"
                       name="title"
                       th:value="${message.title}"
                       required>
            </div>

            <!-- 内容 -->
            <div class="mb-3 form-group-spacing">
                <label class="form-label">内容</label>
                <textarea class="form-control"
                          name="content"
                          rows="4"
                          required
                          th:text="${message.content}"></textarea>
            </div>

            <!-- 作者（只读） -->
            <div class="mb-3 form-group-spacing">
                <label class="form-label">作者</label>
                <input type="text"
                       class="form-control"
                       name="writer"
                       th:value="${message.writer}"
                       readonly>
            </div>

            <!-- 提交按钮 -->
            <button type="submit" class="btn btn-primary btn-submit">更新留言</button>
        </form>

        <!-- 返回链接 -->
        <div class="back-link" style="margin-top: 20px; text-align: center;">
            <a th:href="@{/messages/list}" class="text-primary">返回留言列表</a>
        </div>
    </div>
</div>

<script th:src="@{/static/bootstrap-5.3.0/js/bootstrap.bundle.min.js}"></script>
</body>
</html>